const { contextBridge, ipcRenderer } = require("electron");

contextBridge.exposeInMainWorld("electronAPI", {
  "db-query": (sql, params) => ipcRenderer.invoke("db-query", { sql, params }),
  recordStart: (type, startTime) =>
    ipcRenderer.invoke("db-query", {
      sql: `insert into records (type,start_time) values ("${type}" ,"${startTime}")`,
    }),
  recordStop: (type, startTime, duration, endTime) =>
    ipcRenderer.invoke("db-query", {
      sql: `update records set duration = "${duration}" , end_time="${endTime}" where type = "${type}" and start_time = "${startTime}"`,
    }),
  refresh: () =>
    ipcRenderer.invoke("refresh-time", {}),
});
